<?php
  defined('_JEXEC') or die();
  jimport('joomla.application.component.model');
  require_once('base.php');
  
  class PlayerModelPlayer extends BaseModel
  {     
    var $_name        = "player";
    var $_table       = "#__pbny_players";
    
    function get_by_team_id($team){
      $sql = 'SELECT * '.
             'FROM '.$this->_table.
           " WHERE team_id=$team ";
      return $this->_get($sql);
    }
    
    function get_summary_list($id = null){
      
      $t_person   = '#__pbny_persons';
      $t_position = '#__pbny_positions';
      $t_team     = '#__pbny_teams';
      
      $sql = 'SELECT pl.*, concat(p.lastname, \', \', p.firstname) as name, 
            pos.position, t.name as team ' .
             'FROM ' . $this->_table . ' pl ' .
           "LEFT JOIN $t_person p ON p.id=pl.person_id ".
           "LEFT JOIN $t_position pos ON pos.id=pl.position_id ".
           "LEFT JOIN $t_team t ON t.id=pl.team_id";
      
      $where = null;
      if($id)
        $where = ' WHERE id = ' . $id;
      
      $this->_sql = $sql;
          
      return $this->getListData();
    }
    
    function get_by_person_id($person_id){
      $sql = 'SELECT * '.
             'FROM '.$this->_table.
           " WHERE person_id=$person_id";
      return $this->_get($sql, true);
    }
    
    function get_by_division_id($division){
    
      $t_team          = '#__pbny_teams';
      $t_conference_team      = '#__pbny_conference_teams';
      $t_conference        = '#__pbny_conferences';
      $t_division_conference = '#__pbny_division_conferences';
      
      $sql = 'SELECT p.* '.
           'FROM jos_pbny_players p '.
           "LEFT JOIN $t_team t on t.id=p.team_id ".
           "LEFT JOIN $t_conference_team ct on ct.team_id = t.id ".
           "LEFT JOIN $t_conference c on c.id = ct.conference_id ".
           "LEFT JOIN $t_division_conference dc on dc.conference_id = c.id ".
           "WHERE dc.division_id=$division";
           
      return $this->_get($sql);
      
    }
    

  }
?>